package com.ruoyi.storage.controller;

import java.util.List;

import com.ruoyi.storage.domain.ItemDetail;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.storage.domain.EntryRecord;
import com.ruoyi.storage.service.IEntryRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 入库Controller
 * 
 * @author 庞一恺
 * @date 2025-01-20
 */
@RestController
@RequestMapping("/storage/entryRecord")
public class EntryRecordController extends BaseController
{
    @Autowired
    private IEntryRecordService entryRecordService;

    /**
     * 查询入库列表
     */
    @PreAuthorize("@ss.hasPermi('storage:entryRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(EntryRecord entryRecord)
    {
        startPage();
        List<EntryRecord> list = entryRecordService.selectEntryRecordList(entryRecord);
        return getDataTable(list);
    }

    /**
     * 导出入库列表
     */
    @PreAuthorize("@ss.hasPermi('storage:entryRecord:export')")
    @Log(title = "入库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EntryRecord entryRecord)
    {
        List<EntryRecord> list = entryRecordService.selectEntryRecordList(entryRecord);
        ExcelUtil<EntryRecord> util = new ExcelUtil<EntryRecord>(EntryRecord.class);
        util.exportExcel(response, list, "入库数据");
    }

    /**
     * 获取入库详细信息
     */
    @PreAuthorize("@ss.hasPermi('storage:entryRecord:query')")
    @GetMapping(value = "/{batchId}")
    public List<ItemDetail> getInfo(@PathVariable("batchId") String batchId) {
        return entryRecordService.getEntryItemDetailList(batchId);
    }

    /**
     * 新增入库
     */
    @PreAuthorize("@ss.hasPermi('storage:entryRecord:add')")
    @Log(title = "入库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EntryRecord entryRecord)
    {
        return toAjax(entryRecordService.insertEntryRecord(entryRecord));
    }

    /**
     * 修改入库
     */
    @PreAuthorize("@ss.hasPermi('storage:entryRecord:edit')")
    @Log(title = "入库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EntryRecord entryRecord, @RequestParam List<ItemDetail> itemDetails, @RequestParam Integer zoneId)
    {
        return toAjax(entryRecordService.updateEntryRecord(entryRecord, itemDetails, zoneId));
    }

    /**
     * 删除入库
     */
    @PreAuthorize("@ss.hasPermi('storage:entryRecord:remove')")
    @Log(title = "入库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{entryRecordIds}")
    public AjaxResult remove(@PathVariable Integer[] entryRecordIds)
    {
        return toAjax(entryRecordService.deleteEntryRecordByEntryRecordIds(entryRecordIds));
    }
}
